import 'package:encrypt/encrypt.dart';

////https://medium.flutterdevs.com/explore-encrypt-decrypt-data-in-flutter-576425347439
///用户密码加解密和保存
class EncryptData {
  static Encrypted? encrypted;
  static var decrypted;

  static encryptAES(plainText) {
    final key = Key.fromUtf8('@haohaoxuexi,tiantianxiangshang!');
    final iv = IV.fromLength(16);
    final encrypter = Encrypter(AES(key));
    encrypted = encrypter.encrypt(plainText, iv: iv);
  }

  static decryptAES(encryptedText) {
    final key = Key.fromUtf8('@haohaoxuexi,tiantianxiangshang!');
    final iv = IV.fromLength(16);
    final encrypter = Encrypter(AES(key));
    //decrypted = encrypter.decrypt(encrypted!, iv: iv);
    decrypted = encrypter.decrypt64(encryptedText, iv: iv);
  }
}
